﻿// -- MVC4WPF
// -- Copyright © 2009 Information Control Corporation
// -- Revision History:
// -- Version 0.9.0.0 First codeplex release  - Stephen Giffin

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;

namespace MVC4WPF
{
    /// <summary>
    /// Controller for a WPF based view class, this interface implements the basic properties and events needed for controller to controller communications.
    /// </summary>
    public interface IWPFController : IDisposable, INotifyPropertyChanged, INotifyPropertyChanging
    {
        /// <summary>
        /// Holds a reference to the parent window this controller supports. This is optional not all controllers will have a parent window.
        /// </summary>
        Window ParentWindow { get; set; }

        /// <summary>
        /// THe WPF thread dispatcher for the view this controller controls
        /// </summary>
        Dispatcher ViewDispatcher { get; }

        /// <summary>
        /// The view that is controlled by this controller. 
        /// This provides a reference to the view as a WPF framework element, so it can be added to the parents visual tree.
        /// </summary>
        FrameworkElement ControlledView { get; }

        /// <summary>
        /// Allows for a parent controller to tell the child controller to execute a configuration step. 
        /// The goal of this method is to allow for the configuration of the child controllers, view, model and the child controller itself; 
        /// after all of the objects have already been loaded. 
        /// </summary>
        /// <remarks>
        /// This should be called by the implementing controller, or parent controllers after all propertybag
        /// members on the controller have been set, and any other dynamic configurations have been loaded.
        /// </remarks>
        void ConfigureController();

        /// <summary>
        /// Called to see if it's okay to unload the view
        /// </summary>
        /// <returns>
        /// True if it's okay to unload the view, false if not
        /// </returns>
        /// <remarks>
        /// Prior to closing a controller, the parent controller
        /// should call this to see if it's okay to unload the controller.
        /// It gives the child controller a chance to save data prior to unload as well.
        /// In the case where false will be returned it's expected that the
        /// child controller will display a message indicating why the page
        /// cannot be unloadd. 
        /// The default implementation of QueryunloadPage should return true;
        /// </remarks>
        bool QueryUnloadView();
    }
}
